package com.odm.communitymanage.ui.idle

import android.renderscript.Type
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.blankj.utilcode.util.LogUtils
import com.odm.communitymanage.core.bean.IdleData
import com.odm.communitymanage.core.bean.IdleListData
import com.odm.communitymanage.core.net.ApiService
import com.odm.watercard.base.BaseViewModel
import com.rxjava.rxlife.lifeOnMain
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers
import rxhttp.asClass
import rxhttp.wrapper.param.RxHttp
import rxhttp.wrapper.utils.GsonUtil
import rxhttp.wrapper.utils.LogUtil

/**
 * @description: 闲置列表 ViewModel
 * @author: ODM
 * @date: 2020/4/17
 */
class IdleListViewModel : BaseViewModel(){


    private var _idleList : MutableLiveData<List<IdleData>> = MutableLiveData()
    val idleList : LiveData<List<IdleData>> = _idleList

    lateinit var disposable : Disposable

    var selectedTabIndex : Int = 0


    fun getNewestIdleList(){
        disposable = RxHttp.get(ApiService.ALL_IDLE_LIST_NEWEST)
            .asClass(IdleListData::class.java)
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe({
                _idleList.value = it.data
            },{
                LogUtils.e(it.message)
                it.printStackTrace()
            })

    }


    fun getUpPriceIdleList(){
        disposable = RxHttp.get(ApiService.ALL_IDLE_LIST_UP)
            .asClass(IdleListData::class.java)
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe({
                _idleList.value = it.data
            },{
                LogUtils.e(it.message)
                it.printStackTrace()
            })
    }


    fun getDownPriceIdleList(){
        disposable = RxHttp.get(ApiService.ALL_IDLE_LIST_DOWN)
            .asClass(IdleListData::class.java)
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe({
                _idleList.value = it.data
            },{
                LogUtils.e(it.message)
                it.printStackTrace()
            })
    }

    fun findIdleList(content : String ){
        disposable = RxHttp.postJson(ApiService.FIND_IDLE)
            .add("content",content)
            .asClass(IdleListData::class.java)
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe({
                _idleList.value = it.data
            },{
                LogUtils.e(it.message)
                it.printStackTrace()
            })
    }


}